#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:zhangcong
# Email:zc_92@sina.com


from django import template
from django.utils.safestring import mark_safe
register = template.Library()


# 获取_id, 模板语言取 obj._id 会报错
@register.simple_tag
def get_id(obj):
    return obj["_id"]


# 判断是不是栏目id ,如果是则加上 selected 标签
@register.simple_tag
def is_column_id(obj, article_obj):
    if obj["_id"] == article_obj["column_id"]:
        return "selected"


# 获取创建用户的名称,表示谁创建了这个用户
@register.simple_tag
def get_create_username(user_data, create_user_id):
    if create_user_id:
        return user_data[create_user_id]
    else:
        return "系统"


@register.simple_tag
def str_cut(content, length):
    return content[:length]